package simulation;

import agents.Oeuvre;
import sim.engine.SimState;
import sim.engine.Steppable;
import sim.util.Bag;

@SuppressWarnings("serial")
public class Styles implements Steppable  {

	public static Bag styles = new Bag();
	
	public static int ancienete = 0;
	
	public static float popRandB = 0;
	public static float popRap = 0;
	public static float popPopRock = 0;
	public static float popCountry = 0;
	public static float popFolk = 0;
	public static float popBlues = 0;
	public static float popReggae = 0;
	public static float popElectronic = 0;
	
	public static float ClickpopRandB = 0;
	public static float ClickpopRap = 0;
	public static float ClickpopPopRock = 0;
	public static float ClickpopCountry = 0;
	public static float ClickpopFolk = 0;
	public static float ClickpopBlues = 0;
	public static float ClickpopReggae = 0;
	public static float ClickpopElectronic = 0;
	
	public static float ScoreRandB = 0;
	public static float ScoreRap = 0;
	public static float ScorePopRock = 0;
	public static float ScoreCountry = 0;
	public static float ScoreFolk = 0;
	public static float ScoreBlues = 0;
	public static float ScoreReggae = 0;
	public static float ScoreElectronic = 0;


	public static Bag RandB = new Bag();
	public static Bag Rap = new Bag();
	public static Bag PopRock = new Bag();
	public static Bag Country = new Bag();
	public static Bag Folk = new Bag();
	public static Bag Blues = new Bag();
	public static Bag Reggae = new Bag();
	public static Bag Electronic = new Bag();

	public Styles(){
		String[] SousGenreRandB = {"Contemporary R&B","Early R&B","Soul"};
		String[] SousGenreRap = {"Alternative Rap","Hip-Hop/Urban","Pop-Rap","Reggaeton/Latin Rap"};
		String[] SousGenrePopRock = {"Alternative/Indie Rock","Art-Rock/Experimental","British Invasion","Dance","Europop","Folk/Country Rock","Foreign Language Rock","Hard Rock","Heavy Metal","Pop/Rock","Psychedelic/Garage","Punk/New Wave","Rock & Roll/Roots","Singer/Songwriter","Soft Rock"};
		String[] SousGenreCountry = {"Alternative Country","Contemporary Country","Country-Pop","Honky Tonk","Progressive Country","Traditional Country","Western Swing"};
		String[] SousGenreFolk = {"Contemporary Folk","Traditional Folk"};
		String[] SousGenreBlues = {"Chicago Blues","Classic Electric Blues","Country Blues","Delta Blues","Early Acoustic Blues","East Coast Blues","Electric Blues","Harmonica Blues","Jump Blues/Piano Blues","Louisiana Blues","Modern Electric Blues","Texas Blues"};
		String[] SousGenreReggae = {"Bluebeat","Caribbean Traditions","Contemporary Reggae","Dancehall","DJ/Toasting","Dub","Dub Poetry","Lovers Rock","Nyahbinghi","Political Reggae","Ragga","Reggae-Pop","Rocksteady","Roots Reggae","Ska","Smooth Reggae","Soca","Sound System"};
		String[] SousGenreElectronic = {"Downtempo","Electronica","Experimental Electronic","House","Jungle/DrumnBass","Techno","Trance"};


		addStyle(SousGenreRandB,RandB);
		addStyle(SousGenreRap,Rap);
		addStyle(SousGenrePopRock,PopRock);
		addStyle(SousGenreCountry,Country);
		addStyle(SousGenreFolk,Folk);
		addStyle(SousGenreBlues,Blues);
		addStyle(SousGenreReggae,Reggae);
		addStyle(SousGenreElectronic,Electronic);


	}

	public void addStyle(String[] sousGenre, Bag genre){
		for (int i = 0; i < sousGenre.length; i ++){
			genre.add(sousGenre[i]);
		}
		styles.add(genre);
	}

	public float compareStyle(Bag myStyle, String otherStyle){
		float ret = 0;
		for ( int k = 0; k < myStyle.numObjs; k ++ ){
			if ((String)myStyle.get(k) == otherStyle){
				ret = 1;
			} else {
				for (int i = 0; i < styles.size(); i++){
					Bag temp = (Bag)(styles.get(i));
					if (temp.contains((String)myStyle.get(k)) & temp.contains(otherStyle)){
						ret = (float) 0.5;
					}
				}
			}
		}
		return ret;
	}
	
	public static float populariteStyle(Bag myStyle){
		
		int totalGenres = 0;
		float popGenres = 0;
		Oeuvre temp;
		
		for (int i = 0; i < Simulation.oeuvres.size(); i++){
			temp = ((Oeuvre)Simulation.oeuvres.get(i));
			if( myStyle.contains(temp.genres)){
				
				totalGenres++;
				popGenres += temp.getPopularite();
				
			}
		}
		return (float)(popGenres/totalGenres);
	}
	

	@Override
	public void step(SimState arg0) {
		ancienete++;
		popRandB = populariteStyle(RandB);
		popRap = populariteStyle(Rap);
		popPopRock = populariteStyle(PopRock);
		popCountry = populariteStyle(Country);
		popFolk = populariteStyle(Folk);
		popBlues = populariteStyle(Blues);
		popReggae = populariteStyle(Reggae);
		popElectronic = populariteStyle(Electronic);
	}

}
